package com.xsy.carRental.mapper;

import com.github.pagehelper.Page;
import com.xsy.carRental.dto.RentalPageQueryDTO;
import com.xsy.carRental.dto.RentalSearchQueryDTO;
import com.xsy.carRental.entity.Rental;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface RentalMapper {

    /**
     * 新增订单
     *
     * @param rental
     */
    @Insert("insert into rental (customer_id,vehicle_id,start_date,end_date,total_cost,status,created_at)" +
            "values (#{customerId},#{vehicleId},#{startDate},#{endDate},#{totalCost},#{status},#{createdAt})")
    void add(Rental rental);

    /**
     * 根据订单id查询订单详细信息
     *
     * @param rentalId
     * @return
     */
    @Select("select * from rental where rental_id = #{rentalId}")
    Rental getRentalById(int rentalId);

    void update(Rental rental);

    /**
     * 根据订单id删除订单
     *
     * @param rentalId
     */
    @Delete("delete from rental where rental_id=#{rentalId}")
    void delete(Integer rentalId);

    /**
     * 分页查询订单
     *
     * @param rentalPageQueryDTO
     * @return
     */
    Page<Rental> pageQuery(RentalPageQueryDTO rentalPageQueryDTO);

    Page<Rental> SearchQuery(RentalSearchQueryDTO searchQueryDTO);
}
